package com.sanpu.kxe.business.main.view;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;

import com.sanpu.kxe.R;
import com.sanpu.kxe.base.BaseTitleActivity;
import com.sanpu.kxe.business.main.contract.AdviceInitiateContract;
import com.sanpu.kxe.business.main.contract.MainConfig;
import com.sanpu.kxe.business.main.presenter.AdviceInitiatePresenter;
import com.sanpu.kxe.module.widget.EditTextWithDel;
import com.sanpu.kxe.utils.SoftInputUtil;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * Description：法律咨询
 * Created by 薛勇军 on 2019/3/12.
 */

public class AdviceInitiateActivity extends BaseTitleActivity implements AdviceInitiateContract.View {

    @Bind(R.id.containLayout)
    LinearLayout containLayout;
    @Bind(R.id.contactTv)
    EditTextWithDel contactTv;
    @Bind(R.id.phoneTv)
    EditTextWithDel phoneTv;
    @Bind(R.id.questionEt)
    EditText questionEt;


    private AdviceInitiateContract.Presenter mPresenter;

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_law_advice;
    }

    @Override
    protected void initView() {
        super.initView();
        String mCurrentType = getIntent().getStringExtra(MainConfig.INTENT_ADVICE_TYPE);
        String title = getIntent().getStringExtra(MainConfig.INTENT_ADVICE_TITLE);
        if (!TextUtils.isEmpty(title)) {
            commonTitle.setTitle(title);
        }
        mPresenter = new AdviceInitiatePresenter(this);
        mPresenter.initViewData(mCurrentType);
    }

    @OnClick({R.id.comfirmRtv})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.comfirmRtv:
                //提交咨询问题
                mPresenter.conmitTask(contactTv.getText().toString(),
                        phoneTv.getText().toString(), questionEt.getText().toString());
                break;
        }
    }

    @Override
    public void showDataView(String crpNm, String userName) {
        if (!TextUtils.isEmpty(crpNm)) {
            contactTv.setText(crpNm);
        }
        if (!TextUtils.isEmpty(userName)) {
            phoneTv.setText(userName);
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        SoftInputUtil.hideSoftInput(this);
    }

    @Override
    protected boolean hasBindEventBus() {
        return false;
    }

    @Override
    public void setPresenter(AdviceInitiateContract.Presenter presenter) {
        this.mPresenter = presenter;
    }

    @Override
    public Context getContext() {
        return this;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mPresenter != null) {
            mPresenter.onDestroyPresenter();
            mPresenter = null;
        }
    }
}
